<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<!--{include file='comm/header.tpl'}-->
    <link rel="stylesheet" type="text/css" href="/framework/JSCal2/src/css/jscal2.css" />
    <link rel="stylesheet" type="text/css" href="/framework/JSCal2/src/css/border-radius.css" />
    <link rel="stylesheet" type="text/css" href="/framework/JSCal2/src/css/steel/steel.css" />
    <script src="/framework/JSCal2/src/js/jscal2.js"></script>
    <script src="/framework/JSCal2/src/js/lang/cn.js"></script>

    <!--{if $operFlg == 1}-->
    <title>投票添加</title>
    <!--{else}-->
    <title>投票编辑</title>
    <!--{/if}-->
<script>
	var source = {
		check: function(){
			var vote_category = $('#vote_category').val();
			var vote_name = $('#vote_name').val();
			var start_time = $('#start_time').val();
			var end_time = $('#end_time').val();
			var can_multi = $('input:radio[name="can_multi"]:checked').val();
			var options = $('#options').find("option").attr("selected",true);
			var error_msg = '';
			if (vote_category == ''){
				error_msg += '投票分类不能为空<br/>';
			}
			if (vote_name == ''){
				error_msg += '投票主题不能为空<br/>';
			}
			if (start_time == ''){
				error_msg += '开始时间不能为空<br/>';
			}
			if (end_time == ''){
				error_msg += '结束时间不能为空<br/>';
			}
			if (can_multi == ''){
				error_msg += '是否可以多选不能为空<br/>';
			}
			if (options.length == 0){
				error_msg += '投票选项不能为空<br/>';
			}
			if (error_msg != ''){
				E.alert(error_msg);
			}else {
                source.edit();
			}
		},
		
		edit: function(){
			var addForm = $('#addForm').serializeArray();
			$.ajax({
				type: "POST",
				<!--{if $operFlg == 1}-->
                url: "/invokingAjax-backend/content/vote.ajax?operFlg=2",
				<!--{else}-->
				url: "/invokingAjax-backend/content/vote.ajax?operFlg=3",
				<!--{/if}-->
                dataType: "JSON",
				data: addForm,
				success: function( result_obj ) {
                    if (result_obj.code == 200) {
                        E.opener("source.load");
                        <!--{if $operFlg == 1}-->
                        E.alert(result_obj.message,  2, "E.refresh");
                        <!--{else}-->
                        E.alert(result_obj.message,  2, "E.closeWindows");
                        <!--{/if}-->
                    } else {
                        E.alert(result_obj.message);
                    }
                }
			});
		}
	}
	
	$(document).ready(function(){
		$("#addOption").click(function (){
			var voteOption = jQuery.trim($("#vote_option").val());
			$("#vote_option").val("");
			if(voteOption == ""){
				return;
			}
			var optionStr = jQuery.trim($("#options").html());
			optionStr += "<option value=" + voteOption + ">" + voteOption +"</option>";
			$("#options").html(optionStr);
			$("#vote_option").select();
		});
		
		$("#options").dblclick( function () {
			$("#options option:selected").remove();
		}); 
	});
	
</script>
</head>
<body>
	<div style="width:100%">
		
		<div class="items clearfix">
			<h2 style="" class="tal">
				<!--{if $operFlg == 1}-->
			    	投票添加
			    <!--{else}-->
			    	投票编辑
			    <!--{/if}-->
			</h2>
			
			<div class="items2">
				<!--{if $error_msg}-->
	            
				<div class="comm-box">
	                <div style="position:relative;color: red;">
	                    <!--{$error_msg}-->
	                </div>
	            </div>
				
	            <!--{else}-->
				
				<form id="addForm" name="addForm" onsubmit="return false;">
					<table>
						<tr>
							<td width="150" class="tar">投票类别：</td>
							<td>
								<select id="vote_category" name="vote_category" style="width:200px;">
									<option value="">请选择</option>
									<option value="1" <!--{if $voteInfo.0->vote_category == 1}--> selected="selected" <!--{/if}-->>首页问卷</option>
									<option value="2" <!--{if $voteInfo.0->vote_category == 2}--> selected="selected" <!--{/if}-->>会员中心</option>
									<option value="3" <!--{if $voteInfo.0->vote_category == 3}--> selected="selected" <!--{/if}-->>分类调查</option>
									<option value="4" <!--{if $voteInfo.0->vote_category == 4}--> selected="selected" <!--{/if}-->>购物流程</option>
								</select>
							</td>
						</tr>
						<tr>
							<td class="tar">投票主题：</td>
							<td width="*" class="td_input" >
								<input type="text" style="width:200px" id="vote_name" name="vote_name" value="<!--{$voteInfo.0->vote_name}-->">
								<input type="hidden" id="vote_uuid" name="vote_uuid" value="<!--{$voteInfo.0->vote_uuid}-->">
							</td>
						</tr>
						<tr>
							<td class="tar">开始时间：</td>
							<td class="td_input">
								<input id='start_time' name='start_time' value="<!--{$voteInfo.0->start_time}-->" type='text' style="width:130px;" readonly="readonly">
								<font color="#FF0000">*</font>
							</td>
						</tr>
						<tr>
							<td class="tar">结束时间：</td>
							<td class="td_input">
								<input id='end_time' name='end_time' value="<!--{$voteInfo.0->end_time}-->" type='text' style="width:130px;" readonly="readonly">
								<font color="#FF0000">*</font>
							</td>
						</tr>
						<tr>
							<td class="tar">是否可以多选：</td>
							<td>
								<!--{if $voteInfo.0->can_multi eq 0}-->
									<input type="radio" name="can_multi" value="0" checked="checked"/>&nbsp;不可&nbsp;&nbsp;
									<input type="radio" name="can_multi" value="1"/>&nbsp;可多选
								<!--{else}-->
									<input type="radio" name="can_multi" value="0"/>&nbsp;不可&nbsp;&nbsp;
									<input type="radio" name="can_multi" value="1" checked="checked"/>&nbsp;可多选
								<!--{/if}-->
							</td>
						</tr>
						<tr>
							<td class="tar">投票选项：</td>
							<td>
								<input type="text" id="vote_option" name="vote_option" style="width:200px;" maxlength="100">
								<input type="button" id="addOption" name="addOption" value="添加选项" class="btn">
							</td>
						</tr>
						<tr>
							<td class="tar"></td>
							<td>
								<select id="options" name="options[]"  multiple style="width:297px;height:100px;">
								<!--{foreach from=$voteInfo item=voteLine}-->
									<option value="<!--{$voteLine->option_name}-->"><!--{$voteLine->option_name}--></option>
								<!--{/foreach}-->
								</select>
								<font color="#FF0000">*</font>
							</td>
						</tr>
					</table>
				</form>
				
				<!--{/if}-->
			</div>
		</div>
		
		<div class="bottom_fixbox">
			<div class="rectbox tac">
	        	<!--{if $operFlg == 1}-->
	        		<input type="button" class="btn" onclick="source.check();" value="添加投票">
				<!--{else if $operFlg == 2}-->
					<input type="button" class="btn" onclick="source.check();" value="修改投票">
				<!--{/if}-->
				<input type="button" class="btn" onclick="E.closeWindows();" value="关闭">
	        </div>
		</div>

	</div>
</body>
</html>
<script>
	var cal =Calendar.setup({
	      onSelect     : function(cal) { cal.hide() }
	});

	cal.manageFields("start_time", "start_time", "%Y-%m-%d");
	cal.manageFields("end_time", "end_time", "%Y-%m-%d" );
//
//	var  error="<!--{$error_msg}-->";
//	if(error !=""){
//		comm_alert(error,0);
//	}
</script>